
package cn.util;

import java.util.Calendar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 *
 * @author 
 */
public class CommonUtil {

	public static String getDate(int addYear, int addMonth, int addDay) {
	    Calendar caledar = Calendar.getInstance();
	    caledar.add(Calendar.YEAR,addYear);
	    caledar.add( Calendar.MONTH,addMonth);
	    caledar.add(Calendar.DAY_OF_MONTH,addDay);

	    int year = caledar.get(Calendar.YEAR);
	    int month = caledar.get(Calendar.MONTH) + 1;
	    int day = caledar.get(Calendar.DAY_OF_MONTH);
	    String date = "";
	    date += year;
	    if (month < 10) {
	      date += "0";
	    }
	    date += month;
	    if (day < 10) {
	      date += "0";
	    }
	    date += day;
	    return date;
	  }
	  public static String getDateAddLink(int addYear, int addMonth, int addDay, String tag) {
		    Calendar caledar = Calendar.getInstance();
		    caledar.add(Calendar.YEAR,addYear);
		    caledar.add( Calendar.MONTH,addMonth);
		    caledar.add(Calendar.DAY_OF_MONTH,addDay);

		    int year = caledar.get(Calendar.YEAR);
		    int month = caledar.get(Calendar.MONTH) + 1;
		    int day = caledar.get(Calendar.DAY_OF_MONTH);
		    String date = "";
		    date += year + tag;
		    if (month < 10) {
		      date += "0";
		    }
		    date += month + tag;
		    if (day < 10) {
		      date += "0";
		    }
		    date += day;
		    return date;
		  }
	  public static String getDate(){
		  String Date="";
		  Date = (new java.text.SimpleDateFormat("yyyyMMddHHmmss")).format(new java.util.Date());
	      return Date;
	  }

	  public static String getTime(int addYear, int addMonth, int addDay,
	                               int addHour, int addMinute, int addSecond) {
		  //zhaorr 2009-7-4 crm00015937
	    Calendar caledar = Calendar.getInstance();
	    caledar.add(Calendar.YEAR, addYear);
	    caledar.add(Calendar.MONTH, addMonth);
	    caledar.add(Calendar.DAY_OF_MONTH,addDay);
	   
	    caledar.add(Calendar.HOUR_OF_DAY, addHour);
	    caledar.add(Calendar.MINUTE, addMinute);
	    caledar.add(Calendar.SECOND, addSecond);
	   


	    int year = caledar.get(Calendar.YEAR);
	    int month = caledar.get(Calendar.MONTH) + 1;
	    int day = caledar.get(Calendar.DAY_OF_MONTH);
	    int hour = caledar.get(Calendar.HOUR_OF_DAY);
	    int minute = caledar.get(Calendar.MINUTE);
	    int second = caledar.get(Calendar.SECOND);
	    String date = "";
	    date += year;
	    if (month < 10) {
	      date += "0";
	    }
	    date += month;
	    if (day < 10) {
	      date += "0";
	    }
	    date += day;
	    if (hour < 10) {
	      date += "0";
	    }
	    date += hour;
	    if (minute < 10) {
	      date += "0";
	    }
	    date += minute;
	    if (second < 10) {
	      date += "0";
	    }
	    date += second;
	    return date;
	  }
	public static boolean checkHasLogin(HttpServletRequest request) {
		HttpSession session=request.getSession();
		Object obj=session.getAttribute("acc_id");
		Object com=session.getAttribute("comAndRoleInfo");
		if(obj==null||com==null)
			return false;
		else
			return true;
	}

}
